package com.efast.dmom.mes.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.PartGroupItem;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.PartGroupItemService;

/**
 * To achieve the partGroupItem to add, delete, update and query
 * 
 * @author wj
 * @Date 2020/4/1
 */
@Controller
@RequestMapping(value = "/partGroupItem")
public class PartGroupItemController {
	
	@Autowired
	private PartGroupItemService partGroupItemService;
	
	@RequestMapping(value = "/operateByPartGroupItem")
	public @ResponseBody ResultBean operateByPartGroup(@RequestBody PartGroupItem partGroupItem) {
		ResultBean resultBean = new ResultBean(true,' ');
		// Judge to add
		if (partGroupItem.getModificationFlag()== IModificationFlags.NEW) {
			return partGroupItemService.save(partGroupItem);
		// Judge to update
		} else if (partGroupItem.getModificationFlag() == IModificationFlags.MODIFIED) {
			return partGroupItemService.update(partGroupItem);
		// Judge to delete
		} else if (partGroupItem.getModificationFlag() == IModificationFlags.DELETED) {
			return partGroupItemService.delete(partGroupItem);
		}
		return resultBean;
	}
	
	@RequestMapping(value = "/deleteBatch")
	public @ResponseBody ResultBean deleteBatch(@RequestBody List<PartGroupItem> groupItemList) {
		return partGroupItemService.deleteBatch(groupItemList);
	}

}
